package com.yanyeori.framework.jira.jiraclient.greenhopper;

import com.yanyeori.framework.jira.jiraclient.Field;
import net.sf.json.JSONObject;

/**
 * GreenHopper estimate statistics for rapid views.
 */
public class EstimateStatistic {

    private String statFieldId;
    private Double statFieldValue = 0.0;
    private String statFieldText = null;

    /**
     * Creates an estimate statistic from a JSON payload.
     *
     * @param json JSON payload
     */
    protected EstimateStatistic(JSONObject json) {
        statFieldId = Field.getString(json.get("statFieldId"));

        if (json.containsKey("statFieldValue") && json.get("statFieldValue") instanceof JSONObject) {
            JSONObject val = (JSONObject) json.get("statFieldValue");

            statFieldValue = Field.getDouble(val.get("value"));
            statFieldText = Field.getString(val.get("text"));
        }
    }

    public String getFieldId() {
        return statFieldId;
    }

    public Double getFieldValue() {
        return statFieldValue;
    }

    public String getFieldText() {
        return statFieldText;
    }
}
